﻿
function setMenu() {
    var CURRENT_URL = window.location.href.split("#")[0].split("?")[0]
    var $BODY = $("body")
        , $SIDEBAR_MENU = $("#sidebar-menu")
        , $SIDEBAR_FOOTER = $(".sidebar-footer")
        , $LEFT_COL = $(".left_col")
        , $RIGHT_COL = $(".right_col")
        , $NAV_MENU = $(".nav_menu")
        , $FOOTER = $("footer");
    $MENU_TOGGLE = $("#menu_toggle")
    var a = function () {
        $RIGHT_COL.css("min-height", $(window).height());
        var a = $BODY.outerHeight()
            , b = $BODY.hasClass("footer_fixed") ? -10 : $FOOTER.height()
            , c = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height()
            , d = a < c ? c : a;
        d -= $NAV_MENU.height() + b,
            $RIGHT_COL.css("min-height", d)
    };
    $SIDEBAR_MENU.find("a").on("click", function (b) {
        var c = $(this).parent();
        c.is(".active") ? (c.removeClass("active active-sm"),
            $("ul:first", c).slideUp(function () {
                a()
            })) : (c.parent().is(".child_menu") ? $BODY.is(".nav-sm") && ($SIDEBAR_MENU.find("li").removeClass("active active-sm"),
                $SIDEBAR_MENU.find("li ul").slideUp()) : ($SIDEBAR_MENU.find("li").removeClass("active active-sm"),
                    $SIDEBAR_MENU.find("li ul").slideUp()),
                c.addClass("active"),
                $("ul:first", c).slideDown(function () {
                    a()
                }))
    });

    $SIDEBAR_MENU.find("a").filter(function () {
        return this.href == CURRENT_URL
    }).parent("li").addClass("current-page").parents("ul").slideDown(function () {
        a()
    }).parent().addClass("active");

}
//#region  string Polyfill 
if (!String.prototype.startsWith) {
    String.prototype.startsWith = function (search, pos) {
        return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
    };
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function (search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

$(document).on('pjax:start', function () {
    if (layer)
        layer.load(2);
    NProgress.start();
});
$(document).on('pjax:end', function () {
    if (layer)
        layer.closeAll();
    NProgress.done();
});
$(document).on('ajax:start', function () {
    if (layer)
        layer.load(2);
    NProgress.start();
});
$(document).on('ajax:end', function () {
    if (layer)
        layer.closeAll();
    NProgress.done();
});

$(document).on('icheck:render', function () {
    $('.icheck').iCheck('destroy');
    $('.icheck').filter('input[type="checkbox"]').iCheck({
        checkboxClass: "icheckbox_flat-green"
    });
    $('.icheck').filter('input[type="checkbox"]').on('ifChanged', function (e) {
        $(e.target)[0].dispatchEvent(new Event('change'));
    });
});

$(document).on('render:end', function () {
    $('.select2').filter('select').select2();
    $('.select2').filter('select').on('select2:select', function (e) {
        $(e.target)[0].dispatchEvent(new Event('change'));
    });
    $('.icheck').filter('input[type="checkbox"]').iCheck({
        checkboxClass: "icheckbox_flat-green"
    });
    $('.icheck').filter('input[type="checkbox"]').on('ifChanged', function (e) {
        $(e.target)[0].dispatchEvent(new Event('change'));
    });
    $('.dateTime').filter('input').daterangepicker({
        singleDatePicker: !0,
        singleClasses: "picker_1",
        locale: {
            format: "YYYY-MM-DD",
            separator: " - ",
            daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
            monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
        }
    }).on('hide.daterangepicker', function (e) {
        $(e.target)[0].dispatchEvent(new Event('input'));
    });
    $('.dateTime').val(null);
});
$(document).on('reset', function () {
    $('.select2').val(null);
    for (var i = 0; i < $('.select2').length; i++) {
        $('.select2')[i].dispatchEvent(new Event('change'));
    }

    $('input').val(null);
    for (var i = 0; i < $('input').length; i++) {
        $('input')[i].dispatchEvent(new Event('input'));
    }
});
$('.logout').on('click', function () {
    window.location.href = "login.html";
});
